<?php
/*
 * @Author: your name
 * @Date: 2020-10-23 17:24:37
 * @LastEditTime: 2020-12-10 17:33:11
 * @LastEditors: Please set LastEditors
 * @Description: 主机列表
 * @FilePath: /special/application/adminapiv3/service/module_manage/disguise/HostService.php
 */
namespace app\adminapiv3\service\module_manage\disguise;

use app\adminapiv3\service\CommonHostService;
use app\common\service\module_manage\disguise\HostGuiseConfig;
use app\common\service\module_manage\disguise\HostGuisePort;

class DisguiseHostService extends CommonHostService
{
    public $module_name = 'disguise';
    /**
     * @name: 设置
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-10-23 17:26:49
     */
    public function config ($hostId_a)
    {
        $HostGuiseConfig = new HostGuiseConfig();

        $config = $HostGuiseConfig->selectByHostId($hostId_a);

        $HostGuisePort = new HostGuisePort();
        $port_a = $HostGuisePort->selectByHostId($hostId_a);
        $hostPort = [];
        foreach ($port_a as $port)
        {
            $hostPort[$port['host_id']]['port'][$port['type']][] = $port['port'];
        }

        $return = [];
        foreach ($config as $v)
        {

            $return[$v['host_id']]['port'] = [
                'middleware' => 0,
                'sql' => 0,
                'standard' => 0,
                'tcp' => '',
                'udp' => '',
            ];
            if (isset($hostPort[$v['host_id']]['port']))
            {
                foreach($hostPort[$v['host_id']]['port'] as $type => $port)
                {
                    $return[$v['host_id']]['port'][$type] = implode(',', $port);
                }
            }
            
            $return[$v['host_id']]['guise_status'] = $v['guise_status'];
        }
        return $return;
    }

    /**
     * @name: 处理列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-10-26 11:06:00
     */
    public function processList ($data)
    {
        if (empty($data))
        {
            return [];
        }
        
        $return = [];

        foreach ($data as  $k => $v)
        {
            $hostId_a[] = $v['id'];
            $this->softwareId_a[] = $v['software_id'];
        }

        $extraData = $this->extraData();
        $moduleData = $this->config($hostId_a);

        foreach ($data as $k => $v)
        {
            $return[$k] = $this->processOne($extraData, $v);
            !isset($moduleData[$v['id']]) ? : $return[$k][$this->module_name] = $moduleData[$v['id']];
        }

        return $return;
    }
}